//
//  CalendarCellView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/2/15.
//

import SwiftUI
//日历 当天试图
struct CalendarDiaryDayItemView: View {
    @EnvironmentObject var themeManager: ThemeManager
    let day: Int
    let isToday: Bool
    let bean: DiaryBean?
    var itemsWidth:Double
    
    var body: some View {
        ZStack {
            let color : Color = bean != nil  ? .white : themeManager.themeColor
            GeometryReader { geometry in
                ZStack {
                    if let diary = bean {
                        if let mediaItem = getMediaItem(diary) {
                            PictureItemView(item: mediaItem, itemWidth: itemsWidth, itemHeight: itemsWidth,  cornerRadius: itemsWidth / 5)
                        }
                        //遮罩
                        Color.hex("333333").opacity(0.10)
                    }
               
                }
            }
            // 日期文字
            Text("\(day)")
                .foregroundColor(color)
                .font(.custom(IFontType.number.rawValue, size: 16))
                .fontWeight(.bold)
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .background(themeManager.themeColor.opacity(0.15))
        .clipShape(RoundedRectangle(cornerRadius: itemsWidth / 5))
        .aspectRatio(1, contentMode: .fit) //设置比例
        .padding(5)
        
    }
    
    func getMediaItem(_ diary: DiaryBean) -> MediaItem? {
        let picture = diary.listDiaryPicture?.first
        let mediaItem = DiaryExt.getMediaItem(picture)
        return mediaItem
    }
}

#Preview {
    CalendarDiaryDayItemView(day: 24, isToday: true, bean: nil, itemsWidth: 100)
}
